package com.wly.ui.common
{
	import com.wly.datapool.define.GlobalDefine;
	import com.wly.datapool.global.GlobalInfo;
	import com.wly.datapool.tower.TowerInfo;
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	public class ItemCell extends MovieClip
	{
		private var _parentClickUI:*;
		private var _index:int = -1;
		private var _tower:TowerInfo;
		private var _towerModel:MovieClip;
		
		public function ItemCell()
		{
			super();
		}
		
		public function set index(val:int):void
		{
			_index = val;
		}
			
		public function set clickUI(clickUI:*):void
		{
			_parentClickUI = clickUI;
			
			if(_parentClickUI)
			{
				addEventListener(MouseEvent.CLICK, onClick);
			}
			else
			{
				removeEventListener(MouseEvent.CLICK, onClick);
			}
		}
		
//		public function addTower():void
//		{
//			if(_tower)
//			{
//				return;
//			}
//			
//			var tower:TowerInfo =  GlobalInfo.selectTower;
//			var cls:Class       = tower.modelClass;
//			_towerModel          = new cls;
//			_towerModel.x        = GlobalDefine.CELL_WIDTH/2;
//			_towerModel.y        = GlobalDefine.CELL_HEIGHT;
//			addChild(_towerModel);
//			_tower = tower;
//		}
		
		public function removeTower():void	
		{
			if(!_tower)
			{
				return;
			}
			removeChild(_towerModel);
			_tower = null;
		}
		
		public function set tower(t:TowerInfo):void
		{
			_tower = t;
		}
		
		public function get tower():TowerInfo
		{
			return _tower;
		}
		
		private function onClick(e:MouseEvent):void
		{
			if(_parentClickUI)
			{
				_parentClickUI.onItemClick(_index);
			}
		}
	}
}